package com.wrial.kind.concurrency;
/*
 * @Author  Wrial
 * @Date Created in 17:48 2020/8/23
 * @Description  按序打印
 */

public class SequencePrintABC {

    public SequencePrintABC() {

    }

    private volatile int count = 0;

    public void first(Runnable printFirst) throws InterruptedException {
        while (count != 0) {
        }
        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        count++;
    }

    public void second(Runnable printSecond) throws InterruptedException {
        while (count != 1) {
        }
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        count++;
    }

    public void third(Runnable printThird) throws InterruptedException {
        while (count != 2) {
        }
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
}
